

SOURCE=./src
INC=./Include
# Define project name here
PROJECT = test
MAINFILE = main

CC=arm-elf-gcc
OBJCOPY=arm-elf-objcopy
LDSCRIPT=target.ld

LINKER_FLAGS=-mthumb -nostartfiles -Xlinker -o$(PROJECT).elf -Xlinker -M -Xlinker -Map=$(PROJECT).map

DEBUG=-g
OPTIM=-O1


CFLAGS= $(DEBUG) \
		$(OPTIM) \
		-T$(LDSCRIPT) \
		-I . \
		-I ..\common \
		-D ROWLEY_LPC23xx \
		-D THUMB_INTERWORK \
		-mcpu=arm7tdmi \
		-D PACK_STRUCT_END=__attribute\(\(packed\)\) \
		-D ALIGN_STRUCT_END=__attribute\(\(aligned\(4\)\)\) \
		-fomit-frame-pointer \
		-mthumb-interwork
						


THUMB_SOURCE= \
		$(SOURCE)/$(MAINFILE).c

ARM_SOURCE= \

THUMB_OBJS = $(THUMB_SOURCE:.c=.o)
ARM_OBJS = $(ARM_SOURCE:.c=.o)


all: clean $(PROJECT).bin $(MAINFILE).axf

$(MAINFILE).axf : $(PROJECT).elf
	cp $(PROJECT).elf Flash/$(MAINFILE).axf

$(PROJECT).bin : $(PROJECT).hex
	$(OBJCOPY) $(PROJECT).elf -O binary $(PROJECT).bin
	 
$(PROJECT).hex : $(PROJECT).elf
	$(OBJCOPY) $(PROJECT).elf -O ihex $(PROJECT).hex

$(PROJECT).elf : $(THUMB_OBJS) $(ARM_OBJS) $(SOURCE)/LPC2300.s Makefile
	$(CC) $(CFLAGS) $(ARM_OBJS) $(THUMB_OBJS) $(LIBS) $(SOURCE)/LPC2300.s $(LINKER_FLAGS) 

$(THUMB_OBJS) : %.o : %.c Makefile
	$(CC) -c $(CFLAGS) -mthumb $< -o $@

$(ARM_OBJS) : %.o : %.c Makefile
	$(CC) -c $(CFLAGS) $< -o $@

clean :
	rm -f $(THUMB_OBJS)
	rm -f $(ARM_OBJS)
	rm -f $(PROJECT).bin
	rm -f $(PROJECT).map
	rm -f $(PROJECT).elf
	rm -f $(PROJECT).hex
	rm -f Flash/$(MAINFILE).axf